package com.eeepay.eeepay_v2.activity;

import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.eeepay.eeepay_v2.R;
import com.eeepay.eeepay_v2.adapter.MerTypeAdapter;
import com.eeepay.eeepay_v2.model.IntoPiecesInfo;
import com.eeepay.eeepay_v2.model.MccType;
import com.eeepay.eeepay_v2.util.Constant;
import com.eeepay.eeepay_v2.util.DataUtils;
import com.eeepay.eeepay_v2.util.SPUtils;
import com.eeepay.v2_library.ui.ABBaseActivity;

import java.util.List;


/**
 * Created by Ching on 2016/7/1.
 * 商户类别二级分类/MCC码界面
 */
public class MccActivity extends ABBaseActivity implements AdapterView.OnItemClickListener {

    private ListView mccLv;
    private List<MccType> mccTypeList;
    private MerTypeAdapter adapter;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_simple_list;
    }

    @Override
    protected void initWidget() {
        mccLv = getViewById(R.id.lv_simple_list);
    }

    @Override
    protected void eventOnClick() {
        Log.d("typeUt"," datas: "+ DataUtils.getInstance().getDatas());
        Intent intent = getIntent();
        if (intent != null) {
            String merType = intent.getStringExtra(Constant.KEY.MERTYPE);
            mccTypeList = DataUtils.getInstance().getDatas().get(merType);
        }

        adapter = new MerTypeAdapter(this, false);
        adapter.addAll(mccTypeList);
        mccLv.setAdapter(adapter);
        mccLv.setOnItemClickListener(this);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        DataUtils.getInstance().setIndustry(mccTypeList.get(position).getSysName(),
                mccTypeList.get(position).getSysValue());
//        IntoPiecesInfo intoPieces = SPUtils.getIntoPieces();
//        intoPieces.setIndustry(mccTypeList.get(position).getSysName());
//        intoPieces.setMcc(mccTypeList.get(position).getSysValue());
//        SPUtils.saveIntoPieces(intoPieces);
        finish();
    }
}
